//
//  FTYButton.m
//  RedWine
//
//  Created by Liufangfang on 2016/12/31.
//  Copyright © 2016年 HuiBangKe. All rights reserved.
//

#import "FTYButton.h"

@implementation FTYButton

+ (FTYButton *)createButtonWithTitle:(NSString *)title tColor:(UIColor *)tColor fontSize:(CGFloat)fSize backGroundColor:(UIColor *)bgColor{

    FTYButton *button = [[FTYButton alloc] init];
    button.backgroundColor = bgColor;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:tColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:fSize];
    
    return button;
}

+ (FTYButton *)createButtonWithImage:(UIImage *)image imageEdgeInsets:(UIEdgeInsets)imageInsets title:(NSString *)title tColor:(UIColor *)tColor titileEdgeInsets:(UIEdgeInsets)titleInsets fontSize:(CGFloat)fSize backGroundColor:(UIColor *)bgColor{

    FTYButton *button = [[FTYButton alloc] init];
    button.backgroundColor = bgColor;
    [button setImage:image forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:tColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:fSize];
    
    [button setImageEdgeInsets:imageInsets];
    [button setTitleEdgeInsets:titleInsets];
    
    return button;
}

+ (FTYButton *)createButtonWithTitle:(NSString *)title tColor:(UIColor *)tColor fontSize:(CGFloat)fSize backGroundColor:(UIColor *)bgColor cornerRadius:(CGFloat)cRadius{
    
    FTYButton *button = [[FTYButton alloc] init];
    button.backgroundColor = bgColor;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:tColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:fSize];
    
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = cRadius;
    
    return button;
}

+ (FTYButton *)createButtonWithTitle:(NSString *)title tColor:(UIColor *)tColor fontSize:(CGFloat)fSize backGroundColor:(UIColor *)bgColor cornerRadius:(CGFloat)cRadius borderColor:(UIColor *)bColor borderWidth:(CGFloat)bWidth{

    FTYButton *button = [[FTYButton alloc] init];
    button.backgroundColor = bgColor;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:tColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:fSize];
    
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = cRadius;
    button.layer.borderColor = bColor.CGColor;
    button.layer.borderWidth = bWidth;
    
    return button;
}

//重写系统自带点击事件
- (void)addTapBlock:(FTYButtonBlock)block{

    _block = block;
    [self addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAction:(UIButton *)button{

    _block(button);
}

@end
